﻿using System.Collections.Generic;

namespace Neo4jConnect
{
    public abstract class PropertyContainer : IPropertyContainer
    {
        private Dictionary<string, string> properties;
                                
        public PropertyContainer()
        {
            properties = new Dictionary<string, string>();
        }
                      
        public bool HasProperty(string key)
        {            
            return properties.ContainsKey(key);
        }

        public string GetProperty(string key)
        {            
            return properties[key];
        }
        
        public IEnumerable<KeyValuePair<string, string>> GetProperties()
        {        
            foreach (var property in properties)
            {
                yield return property;
            }
        }

        public void SetProperty(string key, string value)
        {            
            properties[key] = value;
        }

        public string RemoveProperty(string key)
        {        
            string value;
            if (properties.TryGetValue(key, out value))
            {
                properties.Remove(key);
                return value;
            }
            return null;
        }        
    }
}
